using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MapPanel : BasePanel
{
    static readonly string path = "UI/Panel/MapPanel";
    public MapPanel() : base(new UIType(path)) { }
    public override void OnEnter()
    {
        Debug.Log("MapPanel");
        uitool.GetOrAddComponentInChildren<Button>("skillupdate").onClick.AddListener(() =>
        {
            //Debug.Log("Setting");
            
            Push(new SkillupdatePanel());
        });
        uitool.GetOrAddComponentInChildren<Button>("talent").onClick.AddListener(() =>
        {
            //Debug.Log("Setting");
            Push(new TalentPanel());
        });
        uitool.GetOrAddComponentInChildren<Button>("Cyclopedia").onClick.AddListener(() =>
        {
            Push(new CyclopediaPanel());
        });
        for (int i = 1; i < PlayerData.level; i++)
        {
            uitool.GetOrAddComponentInChildren<Button>("op" + i).interactable = false;
        }
        for (int i = PlayerData.level+1; i <=5; i++)
        {
            uitool.GetOrAddComponentInChildren<Button>("op" + i).enabled = false;
        }
        uitool.GetOrAddComponentInChildren<Button>("op1").onClick.AddListener(() =>
        {
            if (PlayerData.level == 1)
            {
                panelmanager.PopAll();
                GameRoot.Instance.scenesystem.SetScene(new Level1());
            }
                
        });
        uitool.GetOrAddComponentInChildren<Button>("op2").onClick.AddListener(() =>
        {
            if (PlayerData.level == 2)
            {
                panelmanager.PopAll();
                GameRoot.Instance.scenesystem.SetScene(new Level2());
            }
        });
        uitool.GetOrAddComponentInChildren<Button>("op3").onClick.AddListener(() =>
        {
            if (PlayerData.level == 3)
            {
                panelmanager.PopAll();
                GameRoot.Instance.scenesystem.SetScene(new Level3());
            }
        });
        uitool.GetOrAddComponentInChildren<Button>("op4").onClick.AddListener(() =>
        {
            if (PlayerData.level == 4)
            {
                panelmanager.PopAll();
                GameRoot.Instance.scenesystem.SetScene(new Level4());
            }

        });
        uitool.GetOrAddComponentInChildren<Button>("op5").onClick.AddListener(() =>
        {
            if (PlayerData.level == 5)
            {
                panelmanager.PopAll();
                GameRoot.Instance.scenesystem.SetScene(new Level5());
            }
        });
        uitool.GetOrAddComponentInChildren<Button>("ExitButton").onClick.AddListener(() =>
        {
            #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
            #else
                 Application.Quit();
            #endif
        });
        
    }
}
